package com.coocaa.launcher.framework.manager.configdata.dataControll;

import java.util.List;

import org.litepal.crud.DataSupport;

import com.coocaa.launcher.framework.manager.configdata.data.LauncherAppItemTableData;

public class LauncherAppItemDataController {

    public LauncherAppItemDataController() {

    }

    public void insertLauncherAppItemTableData(String dataid, String type, String pattern, String json) {
        LauncherAppItemTableData data = new LauncherAppItemTableData();
        data.setDataid(dataid);
        data.setType(type);
        data.setPattern(pattern);
        data.setJson(json);
        data.save();
    }

    public List<LauncherAppItemTableData> getLauncherAppItemTableDatas() {
        return DataSupport.findAll(LauncherAppItemTableData.class);
    }

    public List<LauncherAppItemTableData> getLauncherAppItemTableDatasSelect(String dataid, String type, String pattern) {
//       String sql =  "select * from XX where ";
        String sql = "";
        if (pattern != null)
            sql += "pattern ='" + pattern + "' ";
        if (dataid != null)
            sql += "and dataid ='" + dataid + "' ";
        if (type != null)
            sql += "and type ='" + type + "' ";
//        DataSupport.findBySQL(sql);
        return DataSupport.where(sql).find(LauncherAppItemTableData.class);
    }

    public void deleteLauncherAppItemTableData(String dataid) {
        DataSupport.deleteAll(LauncherAppItemTableData.class, "dataid = ?", dataid);
    }

    public void updateLauncherAppItemTableData(String dataid, String type, String pattern,
                                               String json) {
        LauncherAppItemTableData data = new LauncherAppItemTableData();
        if (type != null)
            data.setType(type);
        if (pattern != null)
            data.setPattern(pattern);
        if (json != null)
            data.setJson(json);
        data.updateAll("dataid = ?", dataid);
    }

}
